﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Catering.Catering_Page.JieGouJianKong
{
    public partial class EditShiwuYingyang : System.Web.UI.Page
    {

        #region 属性
        private int ColNum;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] == null && string.IsNullOrEmpty(Request.QueryString["id"].ToString()) && Request.QueryString["rid"] == null && string.IsNullOrEmpty(Request.QueryString["rid"].ToString()))
                {
                    Response.Redirect("EditShiwuYingyang.aspx");
                }
                int id = Int32.Parse(Request.QueryString["id"].ToString());
                int rid = Int32.Parse(Request.QueryString["rid"].ToString());
                Catering_Rules.T_RawMaterial rawMaterialRule = new Catering_Rules.T_RawMaterial();
                DataTable dt = rawMaterialRule.GetRawMaterialById(id, 1);
                if (dt.Rows.Count != 0)
                {
                    Label_1.Text = dt.Rows[0][2].ToString();
                    for (int i = 2; i < dt.Columns.Count; i++)
                    {
                        if ((i+1) >= dt.Columns.Count)
                        {
                            break;
                        }
                        //Label lb = form1.FindControl("Label_" + i) as Label;
                        TextBox txt = form1.FindControl("TextBox_" + i) as TextBox;
                        //if (lb != null)
                        //{
                        //    lb.Text = dt.Columns[i+1].ColumnName;
                        //}
                        if (txt != null)
                        {
                            txt.Text = dt.Rows[0][i+1].ToString();
                        }
                        ColNum = i;
                    }
                }
                else
                {
                    Catering_Rules.T_RawMaterial tempRules = new Catering_Rules.T_RawMaterial();
                    Catering_Model.E_RawMaterial model = tempRules.GetModel(id);
                    Label_1.Text = model.RAWName;
                    for (int i = 2; i < dt.Columns.Count - 1; i++)
                    {
                        Label lb = form1.FindControl("Label_" + i) as Label;
                        TextBox txt = form1.FindControl("TextBox_" + i) as TextBox;
                        if (lb != null)
                        {
                            lb.Text = dt.Columns[i+1].ColumnName;
                        }
                        if (txt != null)
                        {
                            txt.Text = "0.00";
                        }
                    }
                }
            }
        }


        protected void Button1_Click1(object sender, EventArgs e)
        {
            string url = string.Format("GridViewShiwuYingyang.aspx?foodId={0}&level={1}",Session["foodid"].ToString(),Session["level"].ToString());
            Response.Redirect(url);
        }
    }
}